package com.kws.merchant.controller;


import com.kws.merchant.domain.Device;
import com.kws.merchant.domain.Item;
import com.kws.merchant.domain.ItemScheme;
import com.kws.merchant.domain.ItemSchemeMerchant;
import com.kws.merchant.domain.po.ItemPo;
import com.kws.merchant.domain.po.SchemePo;
import com.kws.merchant.domain.vo.ItemVo;
import com.kws.merchant.service.ItemSchemeMerchantService;
import com.kws.merchant.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 报价-项目(Item)表控制层
 *
 * @author yxy
 * @since 2024-10-24 14:46:58
 */
@RestController
@Api(tags = "报价-项目(Item)")
@RequestMapping("item")
public class ItemController {
    /**
     * 服务对象
     */
    @Resource
    private ItemService itemService;
    @Autowired
    private ItemSchemeMerchantService itemSchemeMerchantService;

    @PostMapping("/page")
    @ApiOperation(value = "分页查询列表")
    public R<Page<Item>> pageList(@RequestBody ItemPo itemPo) {
        return R.ok(itemService.pageList(itemPo));
    }


    @GetMapping("/listByMerchant")
    @ApiOperation(value = "商家项目列表")
    public R<List<Item>> listByMerchant() {
        return R.ok(itemService.listByMerchant());
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增数据")
    public R add(@RequestBody Item item) {
//        item.setSignStatus(0);//默认未签订
        return R.ok(itemService.save(item));
    }


    @GetMapping("/listByItemId/{itemId}")
    @ApiOperation(value = "根据项目id查询设备")
    public R<List<Device>> listByItemId(@PathVariable Long itemId) {
        return R.ok(itemService.listByItemId(itemId));
    }

    @PostMapping("/addItemScheme")
    @ApiOperation(value = "方案报价处理")
    public R addItemScheme(@RequestBody List<ItemScheme> itemSchemes) {
        return R.ok(itemService.addItemScheme(itemSchemes));
    }

    @PostMapping("/schemeDetailById")
    @ApiOperation(value = "方案报价查看")
    public R<ItemVo> schemeDetailById(@RequestBody SchemePo schemePo) {
        return R.ok(itemService.schemeDetailById(schemePo));
    }

    @PostMapping("/detailScheme")
    @ApiOperation("方案报价管理列表")
    public R<Page<ItemSchemeMerchant>> detailScheme(@RequestBody ItemPo itemPo) {
        return R.ok(itemSchemeMerchantService.pageList(itemPo));
    }

}
